package workTest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

class Hero{
    private String name;
    private int sex;

    public Hero(String name, int sex) {
        this.name = name;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return name + " ," + sex + "岁";
    }
}

public class work03 {
    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<>();
        map.put("公主",new Hero("刘备",36));
        map.put("大将军",new Hero("赵子龙",28));
        map.put("参军",new Hero("魏延",25));
        map.put("军事",new Hero("孔明",26));
        Set set = map.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(map.get(iterator.next()));
        }

        Set<Map.Entry<String,Object>> entries = map.entrySet();
        Iterator<Map.Entry<String, Object>> iterator1 = entries.iterator();
        while (iterator1.hasNext()){
            Map.Entry<String, Object> next = iterator1.next();
            System.out.println(next.getKey() + "  " + next.getValue());
        }
    }
}

